//
//  ClassCollectionReusableView.m
//  AmountBody
//
//  Created by smm on 2017/12/9.
//  Copyright © 2017年 RCMTM. All rights reserved.
//

#import "ClassCollectionReusableView.h"

@implementation ClassCollectionReusableView

-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        [self initSubviews];
    }
    return self;
}

-(instancetype)init
{
    self = [super init];
    if (self) {
        [self initSubviews];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initSubviews];
    }
    return self;
}

-(void)initSubviews
{
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headTouchFunc:)];
    [self addGestureRecognizer:tap];
    _image = [[UIImageView alloc]init];
    _l_image = [[UIImageView alloc]init];
    _leftImage = [[UIImageView alloc]init];
    _rightImage = [[UIImageView alloc]init];
    _centerLabel = [[UILabel alloc]init];
    _contentLabel = [[UILabel alloc]init];
    _newsView = [[UIView alloc]init];
     [_newsView addSubview:_leftImage];
     [_newsView addSubview:_rightImage];
     [_newsView addSubview:_centerLabel];
     [_newsView addSubview:_contentLabel];
    [self addSubview:_newsView];
    [self addSubview:_image];
    [self addSubview:_l_image];
}
-(void)hiddenUI
{
    _image.hidden = YES;
    _l_image.hidden  = YES;
    _newsView.hidden = YES;
    _leftImage.hidden  = YES;
    _rightImage.hidden  = YES;
    _centerLabel.hidden  = YES;
    _contentLabel.hidden  = YES;
}

-(void)loadHeaderWithModel:(ClassModel *)model
{
    _model = model;
    [self hiddenUI];
    switch (_headType) {
        case CollectionHeaderTypeForLunbo:
        {
            [self loadFontHeaderWithModel:model];
        }
            break;
        case CollectionHeaderTypeForFont:
        {
            [self loadFontHeaderWithModel:model];
        }
            break;
        case CollectionHeaderTypeForPhoto:
        {
            [self loadPhotoHeaderWithModel:model];
        }
            break;
        default:
            break;
    }
}
-(void)loadFontHeaderWithModel:(ClassModel *)model
{
    _newsView.hidden = NO;
    _leftImage.hidden  = NO;
    _rightImage.hidden  = NO;
    _centerLabel.hidden  = NO;
    _contentLabel.hidden  = NO;
    CGFloat jianGeH = 5;
    CGFloat head_H = 60;
    CGFloat imageW = 17;
    CGFloat imageH = 25;
    _newsView.frame = CGRectMake(0, _offsetY, _Cell_W, _Cell_H);
    _centerLabel.text = model.name;
    _centerLabel.font = [UIFont systemFontOfSize:24];
    [_centerLabel sizeToFit];
    CGFloat wid = imageW*2+10+_centerLabel.frame.size.width;
    _leftImage.frame = CGRectMake((_Cell_W-wid)/2.0, jianGeH, imageW, imageH);
    _leftImage.image = [UIImage imageNamed:@"@left"];
    _centerLabel.frame = CGRectMake(_leftImage.frame.origin.x+_leftImage.frame.size.width+5, jianGeH, _centerLabel.frame.size.width, 30);
    _rightImage.frame = CGRectMake(_centerLabel.frame.origin.x+_centerLabel.frame.size.width+5, jianGeH, imageW, imageH);
    _rightImage.image = [UIImage imageNamed:@"@right"];
    _contentLabel.text = [NSString stringWithFormat:@"一 %@ 一",model.content];
    _contentLabel.textColor = ShenZi_Color;
    _contentLabel.font = [UIFont systemFontOfSize:18];;
    [_contentLabel sizeToFit];
    _contentLabel.frame = CGRectMake((_Cell_W-_contentLabel.frame.size.width)/2.0, _centerLabel.frame.origin.y+_centerLabel.frame.size.height+jianGeH, _contentLabel.frame.size.width, Nomal_Label_H);
}
-(void)loadPhotoHeaderWithModel:(ClassModel *)model
{
    _image.hidden = NO;
    _l_image.hidden  = NO;
    CGFloat imageW= SCREEN_W;
    CGFloat imageH = SCREEN_W/(2048./600.);
    CGFloat l_imageW = 16;
    CGFloat l_imageH = 16;
    _image.frame = CGRectMake(0, 0, imageW, imageH);
//    [_image sd_setImageWithURL:[NSURL URLWithString:model.imageUrl] placeholderImage:[UIImage imageNamed:@"nv_c1"]];
    _image.image = [UIImage imageNamed:model.imageUrl];
    _l_image.frame = CGRectMake(imageW-l_imageW*2, imageH-l_imageH, l_imageW, l_imageH);
    _l_image.image = [UIImage imageNamed:@"sanjiao"];
  
}

#pragma mark -  手势按钮方法
-(void)headTouchFunc:(UITapGestureRecognizer*)tap
{
    if (_headBlock) {
        _headBlock(_model);
    }
}

static HeaderTouchBlock _headBlock;
+(void)blockForHeadTouch:(HeaderTouchBlock)headBlock
{
    _headBlock = headBlock;
}

@end
